<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Implicit Object</title>
<style type="text/css">
	table td{
		/* text-align: center; */
	}
	table{
		border-collapse:collapse;
	}
</style>
</head>
<body>
	<table border="1" align="center">
		<tr>
			<th>内置对象</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>request</td>
			<td>HttpServletRequest</td>
			<td></td>
		</tr>
		<tr>
			<td>response</td>
			<td>HttpServletResponse</td>
			<td></td>
		</tr>
		<tr>
			<td>config</td>
			<td>ServletConfig</td>
			<td></td>
		</tr>
		<tr>
			<td>application</td>
			<td>ServletContext</td>
			<td></td>
		</tr>
		<tr>
			<td>session</td>
			<td>HttpSession</td>
			<td></td>
		</tr>
		<tr>
			<td>exception</td>
			<td>Throwable</td>
			<td></td>
		</tr>
		<tr>
			<td>out</td>
			<td>JspWriter</td>
			<td>相当于带缓冲的 PrintWriter</td>
		</tr>
		<tr>
			<td>page</td>
			<td>Object(this)</td>
			<td></td>
		</tr>
		<tr>
			<td>pageContext</td>
			<td>PageContext</td>
			<td></td>
		</tr>
	</table>
	 
	<%
		for(int i=0;i<1024;i++){
			out.write("a");
		}
		//out.flush();	//神奇了！！！用了这个下面转发、重定向都不成功！！！
		response.getWriter().write("<hr/>比较使不使用 flush 的区别<br/>这会出现在最前面，因为 out 有缓冲区，需要 flush 或者关闭或者满了才会输出");
	%>
		<br/>
	<%
		out.write(out.getBufferSize() + "" + "<br/>");
		out.write(out.getRemaining() + "" + "<br/>");
	%>
	<hr/>
	<%
		out.write("pageContext 是 JSP 的上下文对象：" + "<br/>");
		out.write("1. 可以获取其他八个内置对象；" + "<br/>");
		out.write("2. 是一个域对象，用于共享数据。" + "<br/>");
		pageContext.setAttribute("message", "page message...<br/>");
		pageContext.setAttribute("message", "request message...<br/>", pageContext.REQUEST_SCOPE);
		pageContext.setAttribute("message", "session message...<br/>", pageContext.SESSION_SCOPE);
		pageContext.setAttribute("message", "application message...<br/>", pageContext.APPLICATION_SCOPE);
		//request.setAttribute("message", "request message...");	//等价与上面的代码
	%>
	
	<%
		String message = (String)pageContext.getAttribute("message");
		out.write(message + "<br/>");
	%>
	<%=pageContext.getAttribute("message", pageContext.PAGE_SCOPE) %>
	<%=pageContext.getAttribute("message", pageContext.REQUEST_SCOPE) %>
	<%=request.getAttribute("message") %><%--等价与上面的写法 --%>
	<%=pageContext.getAttribute("message", pageContext.SESSION_SCOPE) %>
	<%=pageContext.getAttribute("message", pageContext.APPLICATION_SCOPE) %>
	<%--自动搜索数据，顺序：page -> request -> session -> context--%>
	<%=pageContext.findAttribute("message") %>
	
	what's happening???
	<%
		response.sendRedirect(request.getContextPath() + "/testScope.jsp");
		//request.getRequestDispatcher("/testScope.jsp").forward(request, response);
	%>
	what's happening???
</body>
</html>